export default {
    clear: (obj) => {
        if (obj) {
            Object.keys(obj).forEach(key => {
                obj[key] = ''
            })
        }
    },
    clearNull: (obj) => {
        if (obj) {
            Object.keys(obj).forEach(key => {
                obj[key] = null
            })
        }
    },
    leftCopy: (obj, source) => {
        let sourceKey = Object.keys(source)
        if (obj && source) {
            Object.keys(obj).forEach(key => {
                if(sourceKey.includes(key)){
                    obj[key] = source[key] == null ?  '' : source[key]
                }
            })
        }
    },
    leftCopyIgnore: (obj, source) => {
        if (obj && source) {
            Object.keys(obj).forEach(key => {
                if (source[key]) {obj[key] = source[key]}
            })
        }
    },
    hasEnd: (flowId) => {
        return flowId && (flowId == 2 || flowId == 3)
    },
    stopCurrentPage: ()=>{
        if(window.history.length===1){
            window.close()
        }else{
            window.history.back()
        }
    },
    refreshCurrentPage: ()=>{
        if(window.location.hash && window.location.hash.startsWith("#/extra")){
            window.location.reload()
        }
    },
    isPicture: (url = '')=>{
        let strFilter=[".jpeg",".gif", ".jpg",".png",".bmp",".pic",".svg",]
        if (url == null){
            return false;
        }
        if(url.indexOf(".")>-1)
        {
            let p = url.lastIndexOf(".");
            let strPostfix=url.substring(p,url.length)
            strPostfix = strPostfix.toLowerCase();
            for(let sf of strFilter){
                if(strPostfix.startsWith(sf))
                {
                    return true;
                }
            }
        }
        return false;
    },
    toString: (s) => {
        if(s === null || s=== undefined){
            return ""
        }else{
            return  s+ ""
        }
    }
}
